package com.zunipe.screen;

import com.zunipe.until.Util;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ScreenTexts;
import net.minecraft.client.gui.screen.option.OptionsScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.CyclingButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;

public class AutoAttackOptionScreen extends Screen
{
    private final Screen parent;

    protected AutoAttackOptionScreen(Screen screen)
    {
        super(new LiteralText("设置"));
        this.parent = screen;
    }

    @Override
    protected void init()
    {
        this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 168, 200, 20, ScreenTexts.DONE, button -> this.client.setScreen(this.parent)));
        this.addDrawableChild(CyclingButtonWidget.builder(AutoAttackOptionScreen.AttackTarget::getTranslatableName).values(AutoAttackOptionScreen.AttackTarget.values()).initially(Util.attackTarget).build(this.width / 2 - 100, this.height / 6 + 143, 200, 20, new LiteralText("攻击目标"), (a, b) -> Util.attackTarget = b));
        this.addDrawableChild(CyclingButtonWidget.builder(AutoAttackOptionScreen.AttackMode::getTranslatableName).values(AutoAttackOptionScreen.AttackMode.values()).initially(Util.attackMode).build(this.width / 2 - 100, this.height / 6 + 118, 200, 20, new LiteralText("攻击模式"), (a, b) -> Util.attackMode = b));

        this.addDrawableChild(new ScreenUtil.OptionSlider(this.width / 2 - 100, this.height / 6 + 93, 200, 20, (Util.tick - 50) / 4950.0, (e) ->
                e.setMessage(new LiteralText("攻击间隔 " + Util.tick + " 毫秒")), (e) -> Util.tick = (int) (50 + 4950 * e.getValue())));
        this.addDrawableChild(new ScreenUtil.OptionSlider(this.width / 2 - 100, this.height / 6 + 43, 200, 20, (Util.detectDistance - 1) / 299.0, (e) ->
                e.setMessage(new LiteralText("检测距离 " + Util.detectDistance)), (e) -> Util.detectDistance = (int) (1 + 299.0 * e.getValue())));
        this.addDrawableChild(new ScreenUtil.OptionSlider(this.width / 2 - 100, this.height / 6 + 18, 200, 20, (Util.yawScope - 1) / 179.0, (e) ->
        {
            if (Util.pitchScope < 90)
                e.setMessage(new LiteralText("垂直最大转动角度 " + Util.pitchScope));
            else
                e.setMessage(new LiteralText("垂直最大转动角度 无限制"));
        }, (e) -> Util.pitchScope = (int) (1 + 89.0 * e.getValue())));
        this.addDrawableChild(new ScreenUtil.OptionSlider(this.width / 2 - 100, this.height / 6 - 7, 200, 20, (Util.pitchScope - 1) / 89.0, (e) ->
        {
            if (Util.yawScope < 180)
                e.setMessage(new LiteralText("水平最大转动角度 " + Util.yawScope));
            else
                e.setMessage(new LiteralText("水平最大转动角度 无限制"));
        }, (e) -> Util.yawScope = (int) (1 + 179.0 * e.getValue())));
    }

    @Override
    public void render(MatrixStack matrices, int mouseX, int mouseY, float delta)
    {
        this.renderBackground(matrices);
        OptionsScreen.drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 0xFFFFFF);
        super.render(matrices, mouseX, mouseY, delta);
    }

    public enum AttackMode
    {
        LEFT("左键"), RIGHT("右键"), ALL("两个键一起按");;
        private final String name;

        AttackMode(String name)
        {
            this.name = name;
        }

        public Text getTranslatableName()
        {
            return new LiteralText(this.name);
        }
    }

    public enum AttackTarget
    {
        MONSTER("怪物"), ALL("所有"), PLAYER("玩家");

        private final String name;

        AttackTarget(String name)
        {
            this.name = name;
        }

        public Text getTranslatableName()
        {
            return new LiteralText(this.name);
        }
    }
}
